package panel.mapPanel
{
	import assists.ButtonUtils;
	import assists.HtmlText;
	import assists.Lang;
	import assists.URI;
	import assists.resource.ResourceLoader;
	
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.display.Stage;
	
	import inerface.IMapContainerPanel;
	
	import main.ClientConstants;
	
	import panel.eating.RankBtnGroupList;
	
	public class MapContainerPanel extends Sprite implements IMapContainerPanel
	{
		private var _stage:Stage;
		private var _loader:ResourceLoader;
		private var _lang:Lang;
		private var _uri:URI;
		
		private var btnGroup:RankBtnGroupList;
		private var mapContainer:MapContainer;
		
		private var pathInfoList:Array;

		private var _onShowPath:Function;
		
		public function MapContainerPanel()
		{
			pathInfoList = [];
		}
		
		public function changeData(list:Array):void
		{
			pathInfoList = list;
			
			moveToMap();
		}
		
		public function init(stage:Stage, loader:ResourceLoader, lang:Lang, uri:URI=null):void
		{
			_stage = stage;
			_loader = loader;
			_lang = lang;
			_uri = uri;
			
			initBtn();
		}
		
		private function initBtn():void
		{
			btnGroup = new RankBtnGroupList(_stage,_loader,_uri,_stage.stageWidth,_stage.stageHeight * .1);
			this.addChild(btnGroup);
			btnGroup.y = _stage.stageHeight * ClientConstants.HOME_UP_PER;
			
			var list:Array = [HtmlText.formatSizeColor("<b>查看地图</b>",0xFFFF00,20),HtmlText.formatSizeColor("<b>查看路线</b>",0xFFFF00,20)];
			
			function newShape():Shape
			{
				var btnShape:Shape = new Shape;
				btnShape.graphics.lineStyle(1,0x333333,.5);
				btnShape.graphics.beginFill(0x000000,.5);
				btnShape.graphics.drawRoundRect(0,0,_stage.stageWidth / list.length,_stage.stageHeight * .1,5);
				btnShape.graphics.endFill();
				return btnShape;
			}
			
			var btn1:ButtonUtils = new ButtonUtils(newShape(),moveToMap,list[0]);
			var btn2:ButtonUtils = new ButtonUtils(newShape(),moveToPath,list[1]);
			
			var btnList:Array = [btn2,btn1];
			btnGroup.changeData(btnList);		
		}
		
		private function moveToPath():void
		{
			if(mapContainer){
				mapContainer.x = -100000;//-_stage.stageWidth;
				this.removeChild(mapContainer);
				mapContainer.clear();
				mapContainer = null;
			}
			
			if(_onShowPath is Function){
				_onShowPath(pathInfoList);
			}
		}
		
		public function set onShowPath(func:Function):void
		{
			_onShowPath = func;
		}
		
		private function moveToMap():void
		{
			if(!mapContainer){
				
				mapContainer = new MapContainer(_stage,_loader,_lang,_uri);
				mapContainer.initThis(_stage.stageWidth,_stage.stageHeight * .72);
				this.addChild(mapContainer);
				mapContainer.changeData(pathInfoList);
				mapContainer.y = _stage.stageHeight * (ClientConstants.HOME_UP_PER + .1);
			}
		}
		
		public function clear():void
		{
			if(mapContainer){
				mapContainer.clear();
				mapContainer = null;
			}
		}
	}
}